import 'package:flutter/material.dart';

import 'package:atten_sys/entity/Entity.dart';
import 'package:atten_sys/utils/utils.dart';

class List4Daily extends StatefulWidget {
  final List<Daily> list;
  final String title;

  List4Daily({Key key, @required this.title, @required this.list});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _DailyListState();
  }
}

class _DailyListState extends State<List4Daily> {

  Widget _buildDailyList() {
    List list = widget.list;
    return ListView.builder(
      itemBuilder: (context, i) {
        if (list.isEmpty)
          return ListTile(
            title: Center(
              child: Text('暂无记录'),
            ),
          );

        return _buildListData(context, list[i]);
      },
      itemCount: list.isEmpty ? 1 : list.length,
    );
  }

  Widget _buildListData(BuildContext context, Daily d) {

    TextStyle style = TextStyle(
      fontSize: 16, fontWeight: FontWeight.w500
    );

    TextStyle style2 = TextStyle(
      fontSize: 18, fontWeight: FontWeight.w500
    );

    return Card(
      elevation: 10,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(14))),
      color: Colors.grey[100],
      child: Container(
        child: Column(
          children: <Widget>[
            ListTile(
              title: Text('记录日期：', style: style,),
              subtitle: Text(DateUtil.date2FmtStr(d.generateTime), style: style2,),
            ),
            Divider(),
            ListTile(
              title: Text('考勤开始时间：', style: style,),
              subtitle: Text(d.attendance.startTime, style: style2,),
            ),
            ListTile(
              title: Text('考勤结束时间：', style: style,),
              subtitle: Text(d.attendance.endTime, style: style2,),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: new AppBar(
        title: new Text('${widget.title}'),
      ),
      body: _buildDailyList(),
    );
  }
}
